const Packet = require("../packet");
class ImageResponsePacket {
    constructor() {}

    build(
        v,
        response_type,
        sequence_number,
        timestamp,
        image_data
    ) {
        const packet = new Packet();
        packet
            .fill(v, 4)
            .fill(response_type, 8)
            .fill(sequence_number, 20)
            .fill(timestamp,32)
            .fill(image_data.length, 32)
            .fillChunk(image_data, image_data.length * 8);
        return new Uint8Array(packet.getPacket());
    }

    parse(p) {
        let v,
            response_type,
            sequence_number,
            timestamp,
            image_data_size,
            image_data;
        const packet = new Packet(p);

        v = packet.extract(4);
        response_type = packet.extract(8);
        sequence_number = packet.extract(20);
        timestamp = packet.extract(32);
        image_data_size = packet.extract(32);
        image_data = packet.extractChunk(image_data_size * 8);

        return {
            v,
            response_type,
            sequence_number,
            timestamp,
            image_data
        }
    }
}

module.exports = new ImageResponsePacket();